package com.xlhj.mq.service.impl;

import cn.hutool.core.lang.UUID;
import com.xlhj.mq.service.QueueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.jms.Queue;

/**
 * @ClassName QueueServiceImpl
 * @Description 队列业务接口实现类
 * @Author liucaijing
 * @Date 2020/11/19 22:15
 * @Version 1.0
 */
@Service
public class QueueServiceImpl implements QueueService {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;
    @Autowired
    private Queue queue;

    @Override
    public void producerMessage() {
        jmsMessagingTemplate.convertAndSend(queue, UUID.fastUUID().toString());
    }

    @Override
    @Scheduled(fixedDelay = 3000)
    public void producerMessageScheduled() {
        jmsMessagingTemplate.convertAndSend(queue, UUID.fastUUID().toString());
    }
}
